<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Hoarding;

class HoardingController extends Controller
{

    public function __construct()
    {
        view()->share([
            '_ts' => 'am-in',
            '_listHoarding' => 'am-active',
        ]);

    }
    //囤票活动列表
    public function listHoarding(Request $request){
        $hoardingArr=Hoarding::get();
        return view('admin.hoardingticket.listHoarding',compact('hoardingArr'));
    }

    //新增囤票活动
    public function addHoarding(Request $request){
        return view('admin.hoardingticket.addHoarding');
    }


    //保存或新增囤票信息说明
    public function addOrUpdateHoarding(Request $request){
        Hoarding::addOrUpdate($request->id,$request->discount_price,$request->discount_ratio,$request->ticket_total,$request->days,$request->is_over,$request->start_time,$request->end_time);
        return redirect('admin/listHoarding')->with('success', '操作成功');

    }

    //修改充值面额
    public function updateHoarding($id){
        $hoardingInfo=Hoarding::store($id);
        return view('admin.hoardingticket.updateHoarding',compact('hoardingInfo'));
    }


    //删除充值面额
    public function deleteHoarding($id){
        $status=Hoarding::destroy($id);
        if($status){
            return redirect('admin/listHoarding')->with('success','删除成功');
        }

    }
}
